﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Recon.Portal.Business;
using Recon.Portal.DataObjects;

namespace Recon.Portal.WebUI.Modules
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Menu mnRecon = ((Menu)Master.FindControl("mnReconEngine"));
            mnRecon.Visible = false;
            HyperLink chngPwdLink = ((HyperLink)Master.FindControl("hyprChangePwd"));
            chngPwdLink.Visible = false;
        }

        protected void chngPassword_ChangingPassword(object sender, LoginCancelEventArgs e)
        {
            if (chngPassword.CurrentPassword == chngPassword.NewPassword)
            {
                lblMessage.Text = "* Old password and new password must be different.  Please try again.";
            }
            else
            {
                User loggedUser = (User)HttpContext.Current.Session["CurrentUserVO"];
                UserEntity userEntity = new UserEntity();
                int retValue = userEntity.changePassword(loggedUser, chngPassword.NewPassword);
                if (retValue == 1)
                {
                    //HomeLink.Visible = true;
                    chngPassword.Enabled = false;
                    lblMessage.Text = "* Password changed successfully.";
                    Session.Abandon();
                    Session.Clear();
                    System.Web.Security.FormsAuthentication.SignOut();
                    btnClickPopup.Show();
                }
                else
                {
                    lblMessage.Text = "* Invalid data. Please try again.";
                }
            }
            lblMessage.Visible = true;
            e.Cancel = true;
        }
    }
}